import pymysql


def test_connect_to_mysql():
    try:
        conn = pymysql.connect(
            host="localhost",
            user="root",
            password="root",
            database="test"
        )
        print("连接成功！" if conn.open else "连接失败")
        conn.close()
    except Exception as e:
        print(f"错误: {e}")


if __name__ == "__main__":
    test_connect_to_mysql()
